#include <bits/stdc++.h>
using namespace std;
const int N = 31;
int n;
int w[N], f[N][N], g[N][N];
// g[l][r]用于记录[l, r]区间的根节点

void dfs(int left, int right) {
  if (left > right) return;
  int root = g[left][right];
  // 前序遍历
  cout << root << ' ';
  dfs(left, root - 1);
  dfs(root + 1, right);
}

int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> w[i];
    f[i][i] = w[i];  // 叶节点的权值就是w[i]
    g[i][i] = i;
  }
  for (int len = 2; len <= n; ++len) {
    for (int l = 1; l + len - 1 <= n; ++l) {
      int r = l + len - 1;
      for (int k = l; k <= r; ++k) {
        int l_tr = k == l ? 1 : f[l][k - 1];
        int r_tr = k == r ? 1 : f[k + 1][r];
        int score = l_tr * r_tr + w[k];
        if (score > f[l][r]) {  // 更新
          f[l][r] = score;
          g[l][r] = k;
        }
      }
    }
  }
  cout << f[1][n] << endl;
  dfs(1, n);
}
